package com.news.yp.framelibrary.navigation;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.news.yp.baselibrary.navigation.AbsNavigationBar;
import com.news.yp.framelibrary.R;
/**
 * 默认的Navigationbar
 */

public class DefaultNavigationBar<D extends DefaultNavigationBar.Builder.DefaultNavigationBarParams> extends
        AbsNavigationBar<DefaultNavigationBar.Builder.DefaultNavigationBarParams> {

    DefaultNavigationBar(DefaultNavigationBar.Builder.DefaultNavigationBarParams mparams) {
        super(mparams);
    }

    @Override
    public int bindlayoutId() {
        return R.layout.title_bar;
    }

    @Override
    public void applyView() {
        //绑定效果
        setText(R.id.my_title, getmParams().mTitle);
        setText(R.id.right_text, getmParams().mRightText);
        //点击事件
        setOnClickListener(R.id.right_text, getmParams().mRightClickListener);
        //左边需要写一个finishActivity
        setOnClickListener(R.id.back, getmParams().mLeftClickListener);

    }

    public static class Builder extends AbsNavigationBar.Builder {

        DefaultNavigationBarParams P;

        public Builder(Context context, ViewGroup viewGroup) {

            P = new DefaultNavigationBarParams(context, viewGroup);
        }

        public Builder(Context context) {
            P = new DefaultNavigationBarParams(context, null);
        }

        @Override
        public DefaultNavigationBar builder() {
            DefaultNavigationBar navigationBar = new DefaultNavigationBar(P);
            return navigationBar;
        }

        public DefaultNavigationBar.Builder setTitle(String title) {
            P.mTitle = title;
            return this;
        }

        public DefaultNavigationBar.Builder setRightText(String rightText) {
            P.mRightText = rightText;
            return this;
        }

        public DefaultNavigationBar.Builder setRightClickListener(View.OnClickListener listener) {
            P.mRightClickListener = listener;
            return this;
        }

        public DefaultNavigationBar.Builder setLeftClickListener(View.OnClickListener listener) {
            P.mLeftClickListener = listener;
            return this;
        }

        public DefaultNavigationBar.Builder setRightIcon(int rightIcon) {
            return this;
        }

        public static class DefaultNavigationBarParams extends AbsNavigationBar.Builder.AbsNavigationBarParams {
            //所有效果放置
            public String mTitle;
            public String mRightText;
            public View.OnClickListener mRightClickListener;
            public View.OnClickListener mLeftClickListener = new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    //关闭当前的Activity
                    ((Activity) mContext).finish();
                }
            };

            public DefaultNavigationBarParams(Context context, ViewGroup mParent) {
                super(context, mParent);
            }


        }
    }
}
